package com.asset.troubleticket.dao;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.asset.troubleticket.domain.Employee;

@Repository
public class EmployeeDao {
	@Autowired
	@Qualifier(value="sessionFactory")
	SessionFactory sessionFactory;
	
	
	public void addEmployee(Employee emp){
		try{
			sessionFactory.getCurrentSession().save(emp);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
		
	public void editEmployee(Employee emp){
		try{
			sessionFactory.getCurrentSession().saveOrUpdate(emp);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	public void deleteEmployee(Employee emp){
		try{
			sessionFactory.getCurrentSession().delete(emp);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	public Employee getById(Integer id){
		try{
		return (Employee)	sessionFactory.getCurrentSession().load(Employee.class,id);
			}catch(Exception ex){
				ex.printStackTrace();
				return null;
			}
	}
}
